import { fromJS } from 'immutable';
import * as actionTypes from './actionTypes';

const defaultState = fromJS({
    topicList: [],
    articleList: [],
    recommendList: [],
    articlePage: 1,
    showScroll: false
});

export default (state = defaultState, action) => {
    switch(action.type) {
        case actionTypes.INIT_HOME:
            return state.merge({
                "topicList": action.topicList,
                "articleList": action.articleList,
                "recommendList": action.recommendList
            });
        case actionTypes.LOAD_MORE_ARTICLE:
            return state.set("articleList", state.get("articleList").concat(action.list)).set("articlePage", action.nextPage);
        case actionTypes.SWITCH_TOP_VISIBILITY:
            return state.set("showScroll", action.showScroll);
        default:
            return state;
    }
}